local skill = fk.CreateSkill{
  name = "obliterate_skill",
}

Fk:loadTranslationTable{
  [skill.name] = "湮灭",
  ["#obliterate_skill"] = "选择一名其他角色，弃置其一或三张牌。若为三张，你失去1点体力。",

  ["#obliterate_skill-choose"] = "湮灭：请选择任意张牌弃置",
}

Fk:addPoxiMethod{
  name = "obliteratePoxi",
  prompt = "#obliterate_skill-choose",
  card_filter = Util.TrueFunc,
  feasible = function (selected)
    return #selected == 1 or #selected == 3
  end,
}

---@param room Room
---@param player ServerPlayer
---@param target ServerPlayer
local function chooseCards(room, player, target)
  local cards = {}
  local hand = target:getCardIds("h")
  if #hand > 0 then
    table.insert(cards, {"$Hand", hand})
  end
  local equip = target:getCardIds("e")
  if #equip > 0 then
    table.insert(cards, {"$Equip", equip})
  end

  local visible, hidden = {}, {}
  table.forEach(table.connect(hand, equip), function (id)
    if player:cardVisible(id) then
      table.insert(visible, id)
    else
      table.insert(hidden, id)
    end
  end)
  local visible_data = {}
  table.forEach(hidden, function (id)
    visible_data[tostring(id)] = false
  end)

  local data = {
    to = target.id,
    min = 1,
    max = 3,
    skillName = "obliterate",
    visible_data = visible_data,
  }
  local poxiParams = {
    poxi_type = "obliteratePoxi",
    data = cards,
    extra_data = data,
    cancelable = false
  }

  local ret = room:askToPoxi(player, poxiParams)
  local new_ret = table.filter(ret, function(id) return id ~= -1 end)
  local hidden_num = #ret - #new_ret
  if hidden_num > 0 then
    table.insertTable(new_ret, table.random(hidden, hidden_num))
  end

  return new_ret
end

skill:addEffect("cardskill", {
  prompt = "#obliterate_skill",
  can_use = Util.CanUse,
  target_num = 1,
  mod_target_filter = function (self, player, to_select, selected, card, extra_data)
    return player ~= to_select and not to_select:isNude()
  end,
  target_filter = Util.CardTargetFilter,
  on_effect = function(self, room, effect)
    local cards = chooseCards(room, effect.from, effect.to)
    room:throwCard(cards, "obliterate", effect.to, effect.from)
    if #cards == 3 and effect.from:isAlive() then
      room:loseHp(effect.from, 1, "obliterate")
    end
  end,
})

return skill